package com.cruising.backend.controller;

import com.cruising.backend.entity.Result;
import com.cruising.backend.utils.AliOssUtil;
import com.cruising.backend.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yezi
 * @since 2025-04-21
 */
@Slf4j
@RestController
@RequestMapping("/reportFiles")
public class ReportFilesController {

    @PostMapping("/uploadCoverImg")
    public Result<String> uploadCoverImg(MultipartFile file) throws Exception {
        //把文件的内容存储到本地磁盘上
        String originalFilename = file.getOriginalFilename();
        System.out.println("文件名"+originalFilename);
        //保证文件的名字是唯一的,从而防止文件覆盖
        String filename = UUID.randomUUID().toString()+originalFilename.substring(originalFilename.lastIndexOf("."));
        String url = AliOssUtil.uploadFile(filename,file.getInputStream());
        return ResultUtil.success(url);
    }

}
